//Unittest4 scoreFor
#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>

int main(int argc, char const *argv[])
{
	char* cards[] = {"curse", "estate", "duchy", "province", "copper", "silver", "gold", "adventurer", "council room", "feast", "gardens", "mine", "remodel", "smithy", "village", "baron", "great hall", "minion", "steward", "tribute", "ambassador", "cutpurse", "embargo", "outpost", "salvager", "sea hag", "treasure map", "no card"};
	struct gameState state;
	int player;
	int score;
	int totscore, temp;
	int i;
	int j;
	for(i = 0; i < 10; i++){
		totscore = 0;
		//generate random state
		for (j = 0; j < sizeof(struct gameState); j++) {
			((char*)&state)[i] = floor(Random() * 256);
		}
	
		player = rand() % 5;
		state.deckCount[player] = rand() % 20;
		state.discardCount[player] = rand() % 20;
		state.handCount[player] = rand() % MAX_HAND;

		for(j = 0; j < state.handCount[player]; j++){
			state.hand[player][j] = rand() % 27;
			temp = state.hand[player][j];
			if(temp == 0){
				totscore -= 1;
				printf("Card: %s\t", cards[temp]);
				printf("-1\n");
				printf("Totscore %d\n", totscore);
			} else if(temp == 1 || temp == 16){
				totscore += 1;
				printf("Card: %s\t", cards[temp]);
				printf("+1\n");
				printf("Totscore %d\n", totscore);
			} else if(temp == 2){
				totscore += 3;
				printf("Card: %s\t", cards[temp]);
				printf("+3\n");
				printf("Totscore %d\n", totscore);
			} else if(temp == 3){
				totscore += 6;
				printf("Card: %s\t", cards[temp]);
				printf("+6\n");
				printf("Totscore %d\n", totscore);
			} else if(temp == 10){
				printf("Card: %s\t", cards[temp]);
				totscore += (fullDeckCount(player, 0, &state) / 10 ); 
				printf("+%d\n", fullDeckCount(player, 0, &state) / 10 );
				printf("Totscore %d\n", totscore);
			}
		}
		
		for(j = 0; j < state.discardCount[player]; j++){
			state.discard[player][j] = rand() % 27;
			temp = state.discard[player][j];
			if(temp == 0){
				totscore -= 1;
				printf("Card: %s\t", cards[temp]);
				printf("-1\n");
				printf("Totscore %d\n", totscore);
			} else if(temp == 1 || temp == 16){
				totscore += 1;
				printf("Card: %s\t", cards[temp]);
				printf("+1\n");
				printf("Totscore %d\n", totscore);
			} else if(temp == 2){
				totscore += 3;
				printf("Card: %s\t", cards[temp]);
				printf("+3\n");
				printf("Totscore %d\n", totscore);
			} else if(temp == 3){
				totscore += 6;
				printf("Card: %s\t", cards[temp]);
				printf("+6\n");
				printf("Totscore %d\n", totscore);
			} else if(temp == 10){
				printf("Card: %s\t", cards[temp]);
				totscore += (fullDeckCount(player, 0, &state) / 10 ); 
				printf("+%d\n", fullDeckCount(player, 0, &state) / 10 );
				printf("Totscore %d\n", totscore);
			}
		}
		for(j = 0; j < state.deckCount[player]; j++){
			state.deck[player][j] = rand() % 27;
			temp = state.deck[player][j];
			
			if(temp == 0){
				totscore -= 1;
				printf("Card: %s\t", cards[temp]);
				printf("-1\n");
				printf("Totscore %d\n", totscore);
			} else if(temp == 1 || temp == 16){
				totscore += 1;
				printf("Card: %s\t", cards[temp]);
				printf("+1\n");
				printf("Totscore %d\n", totscore);
			} else if(temp == 2){
				totscore += 3;
				printf("Card: %s\t", cards[temp]);
				printf("+3\n");
				printf("Totscore %d\n", totscore);
			} else if(temp == 3){
				printf("Card: %s\t", cards[temp]);
				printf("+6\n");
				totscore += 6;
				printf("Totscore %d\n", totscore);
			} else if(temp == 10){
				printf("Card: %s\t", cards[temp]);
				totscore += (fullDeckCount(player, 0, &state) / 10 ); 
				printf("+%d\n", fullDeckCount(player, 0, &state) / 10 );
				printf("Totscore %d\n", totscore);
			}
		}
		score = scoreFor(player, &state);
		if(totscore == score){
			printf("Pass\n");
		} else {
			printf("Fail: totscore = %d, score = %d\n", totscore, score);
		}
	}
	return 0;
}